using Digitalmes.Domain.Entities.Mes.Masters;

namespace Digitalmes.Application.Mes.Masters.Lines.Queries;

/// <summary>
/// 产线分页查询命令。
/// </summary>
public record GetLineListWithPagedQuery(
    int PageNumber,
    int PageSize) : IPagedQuery, IRequest<IResult<PagedList<MdLineDto>>>;

internal sealed class GetLineListWithPagedQueryHandler(IRepository<MdLine> repo) : IRequestHandler<GetLineListWithPagedQuery, IResult<PagedList<MdLineDto>>>
{
    public async Task<IResult<PagedList<MdLineDto>>> Handle(GetLineListWithPagedQuery request, CancellationToken cancellationToken)
    {
        var items = await repo.GetPagedListAsync(request.PageNumber, request.PageSize, cancellationToken);
        return Result.From(items.Adapt<PagedList<MdLineDto>>());
    }
}
